﻿//---------------------------------------
// 2020-10-6 
// Wng0@sina.com
// 步兵类 
// --------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Walker : MonoBehaviour
{
    float m_life;
    float m_Speed;
    NavMeshAgent m_Agent;
    Vector3 m_destinationPosition;
    void Start()
    {
        m_life=2.0f; 
        m_Speed=1;
        m_Agent=this.GetComponent<NavMeshAgent>();   
    }
    void Update()
    {
        CalculateLife();
        Move();
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag=="Arrow")
        {
            Debug.Log(this.gameObject.name+other.GetComponent<Arrow>().targetTag);
            if (other.GetComponent<Arrow>().targetTag==RoleCatagory.Walker)
            {
                Debug.Log("Walker was attacked");
                m_life-=1;
            }
        }
    }
    void CalculateLife()
    {
        if (m_life<=0)
        {
            PoolManager.Instance.Despawn(this.gameObject);
        }
    }
    void Move()
    {
        if (m_life<=0)
        {
            return;
        }
        m_destinationPosition=PoolManager.Instance.m_TargetPosition.transform.position;
        m_Agent.speed=m_Speed;
        m_Agent.SetDestination(m_destinationPosition);
    }
}
